package PropsObject;

import com.sxt.GameObject;
import com.sxt.GameWin;

import java.awt.*;

public class BombPropsObj extends PropsObject{
    public BombPropsObj() {
        super();
    }

    public BombPropsObj(String image, GameWin frame) {
        super(image, frame);
    }

    public BombPropsObj(String image, int x, int y, int speedY, GameWin frame) {
        super(image, x, y, speedY, frame);
    }

    @Override
    public void paintSelf(Graphics s) {
        s.drawImage(image,x,y,null);
        existTime--;
        if (existTime<=0){
            this.Frame.PropsisExist = false;
            this.Frame.removeList.add(this);
        }
        //控制道具移动
        if (x>GameWin.WINDOW_WIDTH - PROPS_WIDTH){
            this.speedX = random.nextInt(10)+1;
            speedX*=-1;
        }
        if (x<0){
            this.speedX = random.nextInt(10)+1;
        }
        if (y>GameWin.WINDOW_HEIGHT - PROPS_HEIGHT){
            this.speedY = random.nextInt(5)+1;
            speedY*=-1;
        }
        if (y<0){
            this.speedY = random.nextInt(5)+1;
        }
        x+=speedX;
        y+=speedY;
    }

    public void paintSelf_launch(Graphics graphics){
        //越界回收
        if (y<=0){
            this.y=GameWin.MY_BULLET_VANISH_LOCATION_Y;
            this.x=GameWin.MY_BULLET_VANISH_LOCATION_X;
            this.Frame.removeList.add(this);
        }
        //炸弹发射
        graphics.drawImage(image,x,y,null);
        this.y-=speedX;

        //炸弹与地方单位碰撞检测
        int size = this.Frame.enemyObjList.size();
        for (int i = 0; i < size; i++) {
            GameObject enemyUnit = this.Frame.enemyObjList.get(i);
           if (enemyUnit.getRec().intersects(this.getRec())){
           }
        }
    }

    @Override
    public Rectangle getRec() {
        return new Rectangle(x,y,PROPS_WIDTH,PROPS_HEIGHT);
    }
    @Override
    public void DeBug() {
        System.out.println("BombPropsObj class");
    }
}
